home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 172 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.0 KB

  1. Path: tko.dec.com!diamond
  2. From: diamond@tko.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: atexit() and return from main()
  5. Date: 24 Jan 1996 03:36:33 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4e49g1$8ku@usenet.pa.dec.com>
  8. References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de> <4diicg$i9e@lyra.csx.cam.ac.uk> <TANMOY.96Jan22084309@qcd.lanl.gov> <DLMLL6.A0H@ukpsshp1.serigate.philips.nl>
  9. Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tko.dec.com
  11.  
  12. In article <DLMLL6.A0H@ukpsshp1.serigate.philips.nl>, baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes:
  13. >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
  14. >>In article <DLKrx7.6p6@ukpsshp1.serigate.philips.nl>
  15. >>baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes: 
  16. >>>In this example what happens if no second call to exit is been made (after
  17. >>>longjumping back to main the program does not attempt to call exit again -
  18. >>>instead it keeps executing indefinately)?
  19.  
  20. >>I don't understand the question: are you asking what happens if a program
  21. >>keeps executing indefinitely? Well, it just keeps executing indefinitely.
  22.  
  23. >The question I am asking is if:
  24. >    main() calls setjmp() and then calls exit().  An atexit() function
  25. >    calls longjmp() and returns to main().  main() then continues to
  26. >    execute other code. Is the execution of this code defined behaviour
  27. >    (so long as no attempt is made to exit again)?
  28.  
  29. What do you want?  Execution continues to be defined for a maximum of
  30. 255 C language statements plus whatever library functions are invoked,
  31. and then suddenly becomes undefined?  I sort of think the answer was that
  32. a program that keeps executing indefinitely keeps executing indefinitely.
  33.  
  34. >[Note: There is a large class of programs that never exit at all [...]
  35. >I agree it would be perverse of such a program to make exactly one call
  36. >to exit and then abandon it by a long jump from an atexit function to main.
  37. >One can also construct programs that do this longjump and terminate later
  38. >by calling abort.
  39.  
  40. Why do you suppose there's an IOCCC but no IOCC for other languages?
  41. Anyway, you know how to build yourself an IOCCC entry.  Yes, C permits it.
  42.  
  43. >However I think it is reasonable to ask if it is defined what happens after
  44. >the longjump in the example is made.]
  45.  
  46. Hmm.  Maybe you want undefinition to begin at the point where a powerful
  47. implementation could theoretically detect that the program will never be
  48. able to terminate in a defined manner, instead of waiting until the program
  49. tries to exit again?  Well, what about a daemon with an infinite loop that
  50. neglects to test any termination status?  Should it start as undefined?
  51.  
  52. >A related question - does undefined behaviour invalidate (make undefined)
  53. >all defined behaviour that has gone before?
  54.  
  55. It's hard to argue that defined behavior that went before was really
  56. undefined, but it's easy to argue that this is an irrelevant point.
  57. When undefined behavior makes your disk drive melt, it doesn't matter
  58. if a the files being melted were correctly output by the implementation's
  59. execution of the program.  Less dramatically, undefined behavior can cause
  60. garbage to be scribbed all over your disk, and it still doesn't matter
  61. whether it was good stuff or bad stuff getting erased.
  62.  
  63. >If so does this mean that any program 
  64. >that does not exit() or return from main have any defined behaviour?
  65.  
  66. A program that does not exit() or return from main can still do a bunch
  67. of other stuff, and if all that stuff is defined by the standard then
  68. it has defined behavior.
  69.  
  70. (Incidentally, I still opine that an implementation can finish executing
  71. the program in a finite time if the implementation knows how to make
  72. all the output correct as defined.)
  73. --
  74.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  75. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  76. license, so I can drive in any lane I want, and no innocent victim gets to call
  77. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  78.